<template>
  <div class="my-table">
    <div class="table-toolbar">
      <slot name="addData"></slot>
      <el-input
        placeholder="请输入内容"
        prefix-icon="el-icon-search"
        v-model="search"
        style="width:200px;">
      </el-input>
    </div>
    <el-table
      :data="data"
      stripe
      @sort-change="sortChange"
      style="width: 100%">
      <slot name="column"></slot>
    </el-table>
  </div>
</template>

<script>
  import {mapActions } from 'vuex'

  export default {
    name: 'MyTable',
    props: ['data'],
    data () {
      return {
        search: '',
      }
    },
    computed: {
    },
    watch: {
      search (val) {
        this.setSearchValue(val)
      }
    },
    methods: {
      ...mapActions([
        'setSearchValue'
      ]),
      sortChange (column) {
        console.log(`当前页: ${column}`)
        this.sorts = {
          field: column,
          order: column.order === 'ascending' ? -1 : 0
        }
      },
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
  .my-table
    width 100%

  .el-table
    font-size 16px

  .el-menu
    border-right none
    height 100%

  .el-menu-item.is-active
    background-color #fff

  .table-toolbar
    padding 10px 0
    text-align right
    > *
      margin-left 30px
</style>
